package com.jiazhong.servlets;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.Enumeration;
/*与 05 类似，但可通过配置不同的局部参数，展示 ServletConfig 的 “专属特性”*/
public class ServletTest06 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletConfig servletConfig = this.getServletConfig();
        //根据参数的名称获取参数值
        String param1 = servletConfig.getInitParameter("param1");
        System.out.println(param1);
        //获取所有的参数的名称
        Enumeration<String> initParameterNames = servletConfig.getInitParameterNames();
        //遍历得到的参数的名称
        while (initParameterNames.hasMoreElements()) {
            String string = initParameterNames.nextElement();
            System.out.println(string);
        }

        System.out.println("-----------------");
        //调用config对象
        ServletContext servletContext = this.getServletContext();
        //根据参数的名称获取参数值
        String param = servletContext.getInitParameter("param");
        System.out.println(param1);
        //获取所有的参数的名称
        Enumeration<String> initParameterNames1 = servletContext.getInitParameterNames();
        //遍历得到的参数的名称
        while (initParameterNames.hasMoreElements()) {
            String string = initParameterNames1.nextElement();
            System.out.println(string);
        }
    }
}
